package com.zjs.dao.impl;

import com.zjs.bean.Grade;
import com.zjs.dao.GradeDao;
import com.zjs.utils.DBUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DBUtils implements GradeDao {
    @Override
    public List<Grade> list() {
        String sql = "select * from grade";
        ResultSet resultSet = query(sql, null);
        List<Grade> grades = null;
        try {
            grades = new ArrayList<>();
            while (resultSet.next()) {
                Grade grade = new Grade();
                grade.setGradeId(resultSet.getInt("gradeid"));
                grade.setGradeName(resultSet.getString("gradename"));
                grades.add(grade);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeAll();
        }
        return grades;
    }
}
